package com.government.article.service.impl;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.government.app.bo.KeywordSearchBO;
import com.government.app.bo.KeywordSearchDetailsBO;
import com.government.app.vo.KeywordSearchDetailsVO;
import com.government.app.vo.KeywordSearchVO;
import com.government.app.vo.AppOrgInfoVO;
import com.government.article.domain.ArticlePolicyRel;
import com.government.article.mapper.ArticleMapper;
import com.government.article.mapper.ArticlePolicyMapper;
import com.government.article.mapper.ArticlePolicyRelMapper;
import com.government.article.vo.GetHotInformationVO;
import com.government.common.core.domain.entity.SysDictData;
import com.government.common.core.domain.entity.SysUser;
import com.government.common.core.domain.model.LoginUser;
import com.government.common.utils.SecurityUtils;
import com.government.common.utils.ServletUtils;
import com.government.common.utils.StringUtils;
import com.government.member.domain.UserHobby;
import com.government.member.mapper.UserHobbyMapper;
import com.government.org.domain.OrgInfo;
import com.government.org.mapper.OrgInfoMapper;
import com.government.system.domain.FileUpload;
import com.government.system.domain.UploadFiles;
import com.government.system.mapper.UploadFilesMapper;
import com.government.system.service.ISysDictTypeService;
import com.government.tag.mapper.TagMapper;
import org.apache.commons.compress.utils.Lists;
import org.springframework.transaction.annotation.Transactional;
import com.government.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.government.article.mapper.ArticleInformationMapper;
import com.government.article.domain.ArticleInformation;
import com.government.article.service.IArticleInformationService;

import static com.government.common.utils.PageUtils.startPage;

/**
 * 文章资讯信息Service业务层处理
 *
 * @author system
 * @date 2023-09-20
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ArticleInformationServiceImpl implements IArticleInformationService {
    @Autowired
    private ArticleInformationMapper articleInformationMapper;
    @Autowired
    private UserHobbyMapper userHobbyMapper;
    @Autowired
    private ArticlePolicyRelMapper articlePolicyRelMapper;
    @Autowired
    private ArticlePolicyMapper articlePolicyMapper;
    @Autowired
    private OrgInfoMapper orgInfoMapper;
    @Autowired
    private ArticleMapper articleMapper;
    @Autowired
    private TagMapper tagMapper;
    @Autowired
    private UploadFilesMapper uploadFilesMapper;
    @Autowired
    private ISysDictTypeService dictTypeService;

    /**
     * 查询文章资讯信息
     *
     * @param articleId 文章资讯信息主键
     * @return 文章资讯信息
     */
    @Override
    public ArticleInformation selectArticleInformationByArticleId(Long articleId) {
        return articleInformationMapper.selectArticleInformationByArticleId(articleId);
    }

    /**
     * 查询文章资讯信息列表
     *
     * @param bo
     * @return 文章资讯信息
     */
    @Override
    public List<KeywordSearchVO> selectArticleInformationList(KeywordSearchBO bo) {
        String authorization = ServletUtils.getRequest().getHeader("Authorization");
        SysUser currentUser = null;
        if (StrUtil.isNotBlank(authorization)) {
            // 获取当前的用户
            LoginUser loginUser = SecurityUtils.getLoginUser();
            if (StringUtils.isNotNull(loginUser) && !loginUser.isVisitor()) {
                currentUser = loginUser.getUser();
            }
        }

        startPage();
        List<KeywordSearchVO> result = articleInformationMapper.selectArticleInformationList(bo);
        List<SysDictData> sysDictDataList = dictTypeService.selectDictDataByType("information_nature");
        Map<String, String> informationNatureMap = sysDictDataList.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        List<Long> sourceIds = Lists.newArrayList();
        for (KeywordSearchVO item : result) {
            sourceIds.add(item.getId());
        }
        List<Long> likeFlagIds = Lists.newArrayList();
        List<Long> collectFlagIds = Lists.newArrayList();
        if (Objects.nonNull(currentUser) && CollUtil.isNotEmpty(result)) {
            UserHobby query = new UserHobby();
            query.setUserId(currentUser.getUserId());
            query.setSourceIds(sourceIds);
            query.setType("1");
            query.setSourceType("1");
            likeFlagIds = userHobbyMapper.getUserHobbyFlag(query);
            query.setType("2");
            collectFlagIds = userHobbyMapper.getUserHobbyFlag(query);
        }
        for (KeywordSearchVO item : result) {
            if (Objects.nonNull(currentUser)) {

                if (likeFlagIds.contains(item.getId())) {
                    item.setIsLike("1");
                }
                if (collectFlagIds.contains(item.getId())) {
                    item.setIsCollect("1");
                }
            }
            item.setCharacter(informationNatureMap.get(item.getCharacter()));
            item.setSortTimeStr(DateUtil.formatDate(item.getSortTime()));
            item.setPublishTimeStr(DateUtil.formatDateTime(item.getPublishTime()));
            item.setNew(DateUtil.between(item.getSortTime(), DateUtil.date(), DateUnit.DAY, true) <= 5);

        }

        return result;
    }

    /**
     * 查询文章资讯详情
     *
     * @return 文章资讯信息
     */
    @Override
    public KeywordSearchDetailsVO selectArticleInformationDetails(KeywordSearchDetailsBO bo) {

        String authorization = ServletUtils.getRequest().getHeader("Authorization");
        SysUser currentUser = null;
        if (StrUtil.isNotBlank(authorization)) {
            // 获取当前的用户
            LoginUser loginUser = SecurityUtils.getLoginUser();
            if (StringUtils.isNotNull(loginUser)) {
                currentUser = loginUser.getUser();

            }
        }
        KeywordSearchDetailsVO result = articleInformationMapper.selectArticleInformationDetails(bo);
        if (Objects.nonNull(currentUser)) {
            int likeFlag = userHobbyMapper.selectCount(Wrappers.<UserHobby>lambdaQuery().eq(UserHobby::getUserId, currentUser.getUserId())
                    .eq(UserHobby::getSourceId, result.getId())
                    .eq(UserHobby::getType, "1")
                    .eq(UserHobby::getSourceType, "1"));
            int collectFlag = userHobbyMapper.selectCount(Wrappers.<UserHobby>lambdaQuery().eq(UserHobby::getUserId, currentUser.getUserId())
                    .eq(UserHobby::getSourceId, result.getId())
                    .eq(UserHobby::getType, "2")
                    .eq(UserHobby::getSourceType, "1"));
            result.setIsLike(String.valueOf(likeFlag));
            result.setIsCollect(String.valueOf(collectFlag));

        }
        int count = articlePolicyRelMapper.selectCount(Wrappers.<ArticlePolicyRel>lambdaQuery().eq(ArticlePolicyRel::getArticleId, bo.getId()));
        result.setExistPolicy("0");
        if(count>0) {
            result.setExistPolicy("1");
        }

            // 附件
            if (StrUtil.isNotBlank(result.getAttachmentData())) {

                List<FileUpload> attachmentDataObj = Lists.newArrayList();
                String[] attachmentDatas = result.getAttachmentData().split(",");
                for (String attachmentData : attachmentDatas) {
                    if (StrUtil.isNotBlank(attachmentData)) {
                        UploadFiles uploadFiles = uploadFilesMapper.selectOne(Wrappers.<UploadFiles>lambdaQuery().eq(UploadFiles::getFileUrl, attachmentData));
                        if (Objects.nonNull(uploadFiles)) {
                            FileUpload fileUpload = new FileUpload();
                            if (StrUtil.isNotBlank(result.getCompleteDate()) && DateUtil.parseDate(result.getCompleteDate()).compareTo(DateUtil.parseDate("2023-10-01")) > 0) {
                                fileUpload.setName(uploadFiles.getFromName());
                            }else {
                                fileUpload.setName(uploadFiles.getFileUrl());
                            }
                            fileUpload.setUrl(uploadFiles.getFileUrl());
                            attachmentDataObj.add(fileUpload);
                        }
                    }
                }
                result.setAttachmentDataObjList(attachmentDataObj);
            }
            if (StrUtil.isNotBlank(result.getWorkResult())) {
                List<FileUpload> workResultObj = Lists.newArrayList();
                String[] workResults = result.getWorkResult().split(",");
                for (String workResult : workResults) {
                    if (StrUtil.isNotBlank(workResult)) {
                        UploadFiles uploadFiles = uploadFilesMapper.selectOne(Wrappers.<UploadFiles>lambdaQuery().eq(UploadFiles::getFileUrl, workResult));
                        if (Objects.nonNull(uploadFiles)) {
                            FileUpload fileUpload = new FileUpload();
                            if (StrUtil.isNotBlank(result.getCompleteDate()) && DateUtil.parseDate(result.getCompleteDate()).compareTo(DateUtil.parseDate("2023-10-01")) > 0) {
                                fileUpload.setName(uploadFiles.getFromName());
                            }else {
                                fileUpload.setName(uploadFiles.getFileUrl());
                            }
                            fileUpload.setUrl(uploadFiles.getFileUrl());
                            workResultObj.add(fileUpload);
                        }
                    }
                }

                result.setWorkResultObjList(workResultObj);
            }


//        // 附件
//        if (StrUtil.isNotBlank(result.getAttachmentData())) {
//            String[] attachmentDatas = result.getAttachmentData().split(",");
//            List<String> attachmentDataList = Lists.newArrayList();
//            for (String attachmentData : attachmentDatas) {
//                if (StrUtil.isNotBlank(attachmentData)) {
//                    attachmentDataList.add(attachmentData);
//                }
//            }
//            result.setAttachmentDataList(attachmentDataList);
//        }
//        if (StrUtil.isNotBlank(result.getWorkResult())) {
//            String[] workResults = result.getWorkResult().split(",");
//            List<String> workResultList = Lists.newArrayList();
//            for (String workResult : workResults) {
//                if (StrUtil.isNotBlank(workResult)) {
//                    workResultList.add(workResult);
//                }
//            }
//            result.setWorkResultList(workResultList);
//        }
        List<OrgInfo> orgInfoList = orgInfoMapper.selectList(Wrappers.<OrgInfo>lambdaQuery().select(OrgInfo::getOrgId, OrgInfo::getOrgName));
        Map<Long, String> orgMap = orgInfoList.stream().collect(Collectors.toMap(OrgInfo::getOrgId, OrgInfo::getOrgName));
        // 查询对应部门
        if (StrUtil.isNotBlank(result.getOrgId())) {
            String[] orgIds = result.getOrgId().split(",");
            List<String> orgNames = Lists.newArrayList();
            List<AppOrgInfoVO> appOrgInfoList =Lists.newArrayList();
            for (String orgId : orgIds) {
                orgNames.add("<a href='http://www.touce.com.cn/detail?id=" + orgId + "&searchType=3' style='font-size:14px;' target='_blank'>"+orgMap.get(Long.parseLong(orgId))+"</a>");
//                orgNames.add(orgMap.get(Long.parseLong(orgId)));
                AppOrgInfoVO appOrgInfoVO = new AppOrgInfoVO();
                appOrgInfoVO.setOrgId(orgId);
                appOrgInfoVO.setOrgName(orgMap.get(Long.parseLong(orgId)));
                appOrgInfoList.add(appOrgInfoVO);
            }
            result.setOrgName(String.join(",", orgNames));
            result.setOrgInfoList(appOrgInfoList);
        }

        String content = result.getContent();
        String attachments = result.getAttachments();
        String title = "《@@(.*?)##》";
        Pattern titlePattern = Pattern.compile(title);
        String proof = "（@@(.*?)##）";
        Pattern proofPattern = Pattern.compile(proof);

        if (StrUtil.isNotBlank(content)) {
            Matcher titleMatcher = titlePattern.matcher(content);
            while (titleMatcher.find()) {
                String data = titleMatcher.group(1);
                String articleId = articleMapper.selectArticleIdByTitle(data, "");
                if (StrUtil.isNotBlank(articleId)) {
                    content = content.replace("《@@" + data + "##》", "《<a href='http://www.touce.com.cn/detail?id=" + articleId + "&searchType=1' target='_blank'>" + data + "</a>》");
                } else {
                    content = content.replace("《@@" + data + "##》", "《" + data + "》");
                }
            }
            Matcher proofMatcher = proofPattern.matcher(content);
            while (proofMatcher.find()) {
                String data = proofMatcher.group(1);
                String articleId = articleMapper.selectArticleIdByTitle("", data);
                if (StrUtil.isNotBlank(articleId)) {
                    content = content.replace("（@@" + data + "##）", "（<a href='http://www.touce.com.cn/detail?id=" + articleId + "&searchType=1' target='_blank'>" + data + "</a>）");
                } else {
                    content = content.replace("（@@" + data + "##）", "（" + data + "）");
                }
            }
            result.setContent(content);
        }
        if (StrUtil.isNotBlank(attachments)) {
            Matcher attachmentsTitleMatcher = titlePattern.matcher(attachments);
            while (attachmentsTitleMatcher.find()) {
                String data = attachmentsTitleMatcher.group(1);
                String articleId = articleMapper.selectArticleIdByTitle(data, "");
                if (StrUtil.isNotBlank(articleId)) {
                    attachments = attachments.replace("（@@" + data + "##）", "（<a href='http://www.touce.com.cn/detail?id=" + articleId + "&searchType=1' target='_blank'>" + data + "</a>）");
                } else {
                    attachments = attachments.replace("（@@" + data + "##）", "（" + data + "）");
                }
            }

            Matcher attachmentsProofMatcher = proofPattern.matcher(attachments);
            while (attachmentsProofMatcher.find()) {
                String data = attachmentsProofMatcher.group(1);
                String articleId = articleMapper.selectArticleIdByTitle("", data);
                if (StrUtil.isNotBlank(articleId)) {
                    attachments = attachments.replace("（@@" + data + "##）", "（<a href='http://www.touce.com.cn/detail?id=" + articleId + "&searchType=1' target='_blank'>" + data + "</a>）");
                } else {
                    attachments = attachments.replace("（@@" + data + "##）", "（" + data + "）");
                }
            }
            result.setAttachments(attachments);
        }

//        String content = result.getContent();
//        String attachments = result.getAttachments();
//        String title = "《(.*?)》";
//        Pattern titlePattern = Pattern.compile(title);
//        String proof = "（(.*?)）";
//        Pattern proofPattern = Pattern.compile(proof);
//        Matcher titleMatcher = titlePattern.matcher(content);
//        while (titleMatcher.find()) {
//            String data = titleMatcher.group(1);
//            if (data.contains("@@") && data.contains("##")) {
//                String olddata = data;
//                data = data.replace("<span style=\"font-family: 文鼎ＰＬ简报宋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; color: black;\">", "");
//                data = data.replace("<span lang=\"EN-US\" style=\"font-family: 'Times New Roman',serif; mso-fareast-font-family: 文鼎ＰＬ简报宋; mso-bidi-theme-font: minor-bidi; color: black;\">", "");
//                data = data.replace("<span style=\"font-family: 文鼎ＰＬ简报宋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; color: black; mso-themecolor: text1;\">", "");
//                data = data.replace("<span lang=\"EN-US\" style=\"font-family: 'Times New Roman',serif; mso-fareast-font-family: 文鼎ＰＬ简报宋; mso-bidi-theme-font: minor-bidi; color: black; mso-themecolor: text1;\">", "");
//                data = data.replace("</span>", "");
//                data = data.substring(data.lastIndexOf("@") + 1, data.indexOf("#"));
//                String articleId = articleMapper.selectArticleIdByTitle(data, "");
//                if (StrUtil.isNotBlank(articleId)) {
//                    content = content.replace("《" + olddata + "》", "《<a href='http://www.touce.com.cn/detail?id=" + articleId + "&searchType=1' target='_blank'>" + data + "</a>》");
//                } else {
//                    content = content.replace("《" + olddata + "》", "《" + data + "》");
//                }
//            } else {
//                String articleId = articleMapper.selectArticleIdByTitle(data, "");
//                if (StrUtil.isNotBlank(articleId)) {
//                    content = content.replace("《" + data + "》", "《<a href='http://www.touce.com.cn/detail?id=" + articleId + "&searchType=1' target='_blank'>" + data + "</a>》");
//                } else {
//                    content = content.replace("《" + data + "》", "《" + data + "》");
//                }
//            }
//        }
//
//        Matcher proofMatcher = proofPattern.matcher(content);
//        while (proofMatcher.find()) {
//            String data = proofMatcher.group(1);
//            if (data.contains("@@") && data.contains("##")) {
//                String olddata = data;
//                data = data.replace("<span style=\"font-family: 文鼎ＰＬ简报宋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; color: black;\">", "");
//                data = data.replace("<span lang=\"EN-US\" style=\"font-family: 'Times New Roman',serif; mso-fareast-font-family: 文鼎ＰＬ简报宋; mso-bidi-theme-font: minor-bidi; color: black;\">", "");
//                data = data.replace("<span style=\"font-family: 文鼎ＰＬ简报宋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; color: black; mso-themecolor: text1;\">", "");
//                data = data.replace("<span lang=\"EN-US\" style=\"font-family: 'Times New Roman',serif; mso-fareast-font-family: 文鼎ＰＬ简报宋; mso-bidi-theme-font: minor-bidi; color: black; mso-themecolor: text1;\">", "");
//                data = data.replace("</span>", "");
//                data = data.substring(data.lastIndexOf("@") + 1, data.indexOf("#"));
//                String articleId = articleMapper.selectArticleIdByTitle("", data);
//                if (StrUtil.isNotBlank(articleId)) {
//                    content = content.replace("（" + olddata + "）", "（<a href='http://www.touce.com.cn/detail?id=" + articleId + "&searchType=1' target='_blank'>" + data + "</a>）");
//                } else {
//                    content = content.replace("（" + olddata + "）", "（" + data + "）");
//                }
//            } else {
//                String articleId = articleMapper.selectArticleIdByTitle("", data);
//                if (StrUtil.isNotBlank(articleId)) {
//                    content = content.replace("《" + data + "》", "《<a href='http://www.touce.com.cn/detail?id=" + articleId + "&searchType=1' target='_blank'>" + data + "</a>》");
//                } else {
//                    content = content.replace("《" + data + "》", "《" + data + "》");
//                }
//            }
//        }
//
//        result.setContent(content);
//
//        if (StrUtil.isNotBlank(attachments)) {
//            Matcher attachmentsTitleMatcher = titlePattern.matcher(attachments);
//            while (attachmentsTitleMatcher.find()) {
//                String data = attachmentsTitleMatcher.group(1);
//                if (data.contains("@@") && data.contains("##")) {
//                    String olddata = data;
//                    data = data.replace("<span style=\"font-family: 文鼎ＰＬ简报宋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; color: black;\">", "");
//                    data = data.replace("<span lang=\"EN-US\" style=\"font-family: 'Times New Roman',serif; mso-fareast-font-family: 文鼎ＰＬ简报宋; mso-bidi-theme-font: minor-bidi; color: black;\">", "");
//                    data = data.replace("<span style=\"font-family: 文鼎ＰＬ简报宋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; color: black; mso-themecolor: text1;\">", "");
//                    data = data.replace("<span lang=\"EN-US\" style=\"font-family: 'Times New Roman',serif; mso-fareast-font-family: 文鼎ＰＬ简报宋; mso-bidi-theme-font: minor-bidi; color: black; mso-themecolor: text1;\">", "");
//                    data = data.replace("</span>", "");
//                    data = data.substring(data.lastIndexOf("@") + 1, data.indexOf("#"));
//                    String articleId = articleMapper.selectArticleIdByTitle(data, "");
//                    if (StrUtil.isNotBlank(articleId)) {
//                        attachments = attachments.replace("《" + olddata + "》", "《<a href='http://www.touce.com.cn/detail?id=" + articleId + "&searchType=1' target='_blank'>" + data + "</a>》");
//                    } else {
//                        attachments = attachments.replace("《" + olddata + "》", "《" + data + "》");
//                    }
//                } else {
//                    String articleId = articleMapper.selectArticleIdByTitle(data, "");
//                    if (StrUtil.isNotBlank(articleId)) {
//                        attachments = attachments.replace("《" + data + "》", "《<a href='http://www.touce.com.cn/detail?id=" + articleId + "&searchType=1' target='_blank'>" + data + "</a>》");
//                    } else {
//                        attachments = attachments.replace("《" + data + "》", "《" + data + "》");
//                    }
//                }
//            }
//
//            Matcher attachmentsProofMatcher = proofPattern.matcher(attachments);
//            while (attachmentsProofMatcher.find()) {
//                String data = attachmentsProofMatcher.group(1);
//                if (data.contains("@@") && data.contains("##")) {
//                    String olddata = data;
//                    data = data.replace("<span style=\"font-family: 文鼎ＰＬ简报宋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; color: black;\">", "");
//                    data = data.replace("<span lang=\"EN-US\" style=\"font-family: 'Times New Roman',serif; mso-fareast-font-family: 文鼎ＰＬ简报宋; mso-bidi-theme-font: minor-bidi; color: black;\">", "");
//                    data = data.replace("<span style=\"font-family: 文鼎ＰＬ简报宋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; color: black; mso-themecolor: text1;\">", "");
//                    data = data.replace("<span lang=\"EN-US\" style=\"font-family: 'Times New Roman',serif; mso-fareast-font-family: 文鼎ＰＬ简报宋; mso-bidi-theme-font: minor-bidi; color: black; mso-themecolor: text1;\">", "");
//                    data = data.replace("</span>", "");
//                    data = data.substring(data.lastIndexOf("@") + 1, data.indexOf("#"));
//                    String articleId = articleMapper.selectArticleIdByTitle("", data);
//                    if (StrUtil.isNotBlank(articleId)) {
//                        attachments = attachments.replace("（" + olddata + "）", "（<a href='http://www.touce.com.cn/detail?id=" + articleId + "&searchType=1' target='_blank'>" + data + "</a>）");
//                    } else {
//                        attachments = attachments.replace("（" + olddata + "）", "（" + data + "）");
//                    }
//                } else {
//                    String articleId = articleMapper.selectArticleIdByTitle("", data);
//                    if (StrUtil.isNotBlank(articleId)) {
//                        attachments = attachments.replace("《" + data + "》", "《<a href='http://www.touce.com.cn/detail?id=" + articleId + "&searchType=1' target='_blank'>" + data + "</a>》");
//                    } else {
//                        attachments = attachments.replace("《" + data + "》", "《" + data + "》");
//                    }
//                }
//            }
//            result.setAttachments(attachments);
//        }
        return result;
    }

    /**
     * 新增文章资讯信息
     *
     * @param articleInformation 文章资讯信息
     * @return 结果
     */
    @Override
    public int insertArticleInformation(ArticleInformation articleInformation) {
        articleInformation.setCreateTime(DateUtils.getNowDate());
        return articleInformationMapper.insert(articleInformation);
    }

    /**
     * 修改文章资讯信息
     *
     * @param articleInformation 文章资讯信息
     * @return 结果
     */
    @Override
    public int updateArticleInformation(ArticleInformation articleInformation) {
        articleInformation.setUpdateTime(DateUtils.getNowDate());
        return articleInformationMapper.updateById(articleInformation);
    }

    /**
     * 查询热点资讯
     *
     * @return 结果
     */
    @Override
    public List<GetHotInformationVO> getHotInformation(int type) {
        return articleInformationMapper.getHotInformation(type);
    }

    /**
     * 查询文章资讯信息列表
     *
     * @return 文章资讯信息
     */
    @Override
    public List<KeywordSearchVO> selectInterestInformationList() {

        SysUser currentUser =  SecurityUtils.getLoginUser().getUser();
        KeywordSearchBO bo =new KeywordSearchBO();

        List<UserHobby> userHobbyList  = userHobbyMapper.selectList(Wrappers.<UserHobby>lambdaQuery().select(UserHobby::getSourceId)
                .eq(UserHobby::getType,1)
                .eq(UserHobby::getSourceType,2)
                .eq(UserHobby::getUserId,currentUser.getUserId()));
        if(CollUtil.isEmpty(userHobbyList)){
            return new ArrayList<>();
        }

        List<String> policyIds = new ArrayList<>();
        for (UserHobby userHobby : userHobbyList) {
            policyIds.add(String.valueOf(userHobby.getSourceId()));
        }
        bo.setPolicyIds(policyIds);
        startPage();
        List<KeywordSearchVO> result = articleInformationMapper.selectArticleInformationList(bo);
        List<SysDictData> sysDictDataList = dictTypeService.selectDictDataByType("information_nature");
        Map<String, String> informationNatureMap = sysDictDataList.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        List<Long> sourceIds = Lists.newArrayList();
        for (KeywordSearchVO item : result) {
            sourceIds.add(item.getId());
        }
        List<Long> likeFlagIds = Lists.newArrayList();
        List<Long> collectFlagIds = Lists.newArrayList();
        if (Objects.nonNull(currentUser) && CollUtil.isNotEmpty(result)) {
            UserHobby query = new UserHobby();
            query.setUserId(currentUser.getUserId());
            query.setSourceIds(sourceIds);
            query.setType("1");
            query.setSourceType("1");
            likeFlagIds = userHobbyMapper.getUserHobbyFlag(query);
            query.setType("2");
            collectFlagIds = userHobbyMapper.getUserHobbyFlag(query);
        }
        for (KeywordSearchVO item : result) {
            if (Objects.nonNull(currentUser)) {

                if (likeFlagIds.contains(item.getId())) {
                    item.setIsLike("1");
                }
                if (collectFlagIds.contains(item.getId())) {
                    item.setIsCollect("1");
                }
            }
            item.setCharacter(informationNatureMap.get(item.getCharacter()));
            item.setSortTimeStr(DateUtil.formatDate(item.getSortTime()));
            item.setPublishTimeStr(DateUtil.formatDateTime(item.getPublishTime()));
            item.setNew(DateUtil.between(item.getSortTime(), DateUtil.date(), DateUnit.DAY, true) <= 5);

        }

        return result;
    }

}
